package signfactory

import (
	"fmt"

	"gitee.com/micro-plat/sas/sas/modules/util"
)

//RSASignHandler rsa方法
type RSASignHandler struct{}

//newRSASignHandler 创建对象
func newRSASignHandler() *RSASignHandler {
	return &RSASignHandler{}
}

//Sign 签名
func (o *RSASignHandler) Sign(raw, key, sType, rsaHasType string) (sign string) {
	sign, _ = util.RSASign(raw, key, rsaHasType, sType)
	return
}

//Verify 验证通过
func (o *RSASignHandler) Verify(outSign, raw, key, sType, rsaHasType string) (res bool, err error) {
	res, err = util.RSASignVerify(raw, outSign, key, rsaHasType, sType)
	if err != nil {
		return false, fmt.Errorf("RSASignVerify outSign:%s err:%+v", outSign, err)
	}
	return
}
